/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hotgammon.view;

import hotgammon.domain.game.DeltamonFactory;
import hotgammon.domain.game.Game;
import hotgammon.domain.game.StandardGame;
import hotgammon.view.figures.DieFigure;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import minidraw.framework.DrawingEditor;
import minidraw.framework.Figure;
import minidraw.framework.Tool;

/**
 *
 * @author jeppewelling
 */
public class DieRollTool implements Tool {
    private DrawingEditor window;
    private ArrayList<Figure> dies;
    private Game game;
    private Point[] dicePos;
    DieRollTool(DrawingEditor w) {
        dicePos = new Point[2];    
        dicePos[0] = new Point(216, 202);
        dicePos[1] = new Point(306, 202);
        game = new StandardGame(new DeltamonFactory());
        game.nextTurn();
        window = w;
        dies = new ArrayList<Figure>();
        dies.add(new DieFigure(4, dicePos[0]));
        dies.add(new DieFigure(2, dicePos[1]));
        
        for(Figure die : dies) {
            window.drawing().add(die);
        }
    }

    public void activate() {
        System.out.println("activate");
    }

    public void deactivate() {
        System.out.println("deactivate");
    }

    public void mouseDown(MouseEvent arg0, int left, int top) {
        Figure selected = window.drawing().findFigure(left, top);
        if (selected != null) {
            int i = -1;
            for(Figure die : dies) {
                i++;
                
                Figure newRedDice = new DieFigure(game.diceThrown()[i], dicePos[i]);
                window.drawing().add(newRedDice);   
                window.drawing().remove(die);
            }
            System.out.println(selected.toString());
        }
    }

    public void mouseDrag(MouseEvent arg0, int arg1, int arg2) {
        System.out.println("mouseDrag");
    }

    public void mouseUp(MouseEvent arg0, int arg1, int arg2) {
        System.out.println("mouseUp");
    }

    public void mouseMove(MouseEvent arg0, int arg1, int arg2) {
        System.out.println(arg1 +"  "+ arg2);
    }

    public void keyDown(KeyEvent arg0, int arg1) {
        System.out.println("keyDown");
    }
    
    

}
